using DG.Tweening;
using UnityEngine;
using UnityEngine.UI;

public class DialogHelp : GenericDialog
{
	private const string wasViewedPPKey = "HelpDialogWasViewed";

	public RectTransform pivotRect;

	public Image[] helpImages;

	public Text[] helpLabels;

	public Image[] pageImages;

	private int currentIndex;

	public Button buttonNext;

	public static bool WasViewed()
	{
		return UserPrefs.getBool("HelpDialogWasViewed");
	}

	public override void Start()
	{
		UpdatePivot();
		base.Start();
	}

	private void OnEnable()
	{
		if (Globals.appState != 0 && Globals.appState != AppState.unknown)
		{
			SetFirstPage();
			GenericDialog.FireDialogEnabledEvent();
		}
	}

	private void OnDisable()
	{
		if (Globals.appState != 0 && Globals.appState != AppState.unknown)
		{
			string text = "Next";
			if (currentIndex < 4)
			{
				text = "Step " + (currentIndex + 1);
			}
			CustomAnalytics.LogUIEvent("Help", "Close - " + text);
			UserPrefs.setBool("HelpDialogWasViewed", true);
		}
	}

	private void UpdatePivot()
	{
		if (!(base.rectTransform == null))
		{
			Vector2 size = base.rectTransform.rect.size;
			Vector3 vector = base.rectTransform.InverseTransformPoint(pivotRect.position);
			Vector2 vector2 = new Vector2(vector.x, vector.y);
			vector2.x /= size.x;
			vector2.y /= size.y;
			Vector2 vector3 = base.rectTransform.pivot + vector2;
			Vector2 vector4 = base.rectTransform.pivot - vector3;
			Vector3 vector5 = new Vector3(vector4.x * size.x, vector4.y * size.y);
			base.rectTransform.pivot = vector3;
			base.rectTransform.localPosition -= vector5;
		}
	}

	private void SetFirstPage()
	{
		for (int i = 0; i < pageImages.Length; i++)
		{
			helpImages[i].DOKill();
			helpLabels[i].DOKill();
			if (i == 0)
			{
				pageImages[i].color = Color.white;
				helpImages[i].gameObject.SetActive(true);
				helpLabels[i].gameObject.SetActive(true);
			}
			else
			{
				pageImages[i].color = Color.grey;
				helpImages[i].gameObject.SetActive(false);
				helpLabels[i].gameObject.SetActive(false);
			}
			helpImages[i].color = Utils.SetAlpha(helpImages[i].color, 1f);
			helpLabels[i].color = Utils.SetAlpha(helpLabels[i].color, 1f);
		}
		currentIndex = 0;
		CustomAnalytics.LogUIEvent("Help", "Step 1");
	}

	private void AdvancePage()
	{
		pageImages[currentIndex].color = Color.grey;
		pageImages[currentIndex + 1].color = Color.white;
		Image currHelpImage = helpImages[currentIndex];
		Image nextHelpImage = helpImages[currentIndex + 1];
		nextHelpImage.gameObject.SetActive(true);
		nextHelpImage.color = Utils.SetAlpha(nextHelpImage.color, 0f);
		currHelpImage.DOColor(Utils.SetAlpha(currHelpImage.color, 0f), 0.15f).OnComplete(delegate
		{
			currHelpImage.gameObject.SetActive(false);
			nextHelpImage.DOColor(Utils.SetAlpha(nextHelpImage.color, 1f), 0.15f);
		});
		Text text = helpLabels[currentIndex];
		Text text2 = helpLabels[currentIndex + 1];
		text.gameObject.SetActive(false);
		text2.gameObject.SetActive(true);
		currentIndex++;
		CustomAnalytics.LogUIEvent("Help", "Step " + (currentIndex + 1));
	}

	public void OnButtonNext()
	{
		if (currentIndex < pageImages.Length - 1)
		{
			AdvancePage();
			return;
		}
		currentIndex++;
		UserInterface.GetInstance().CloseModalDialog();
	}
}
